<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/shadow-dom.js"></script>
<div id="targets">
    <div id="T0">
        <div id="normal-target">Normal</div>
    </div>

    <div id="T1">
        <template><div id="target">Shadow</div></template>
    </div>

    <div id="T2">
        <template>
            <div id="H">
                <template><div id="target">Shadow in shadow</div></template>
            </div>
        </template>
    </div>

    <details id="T3"><div id="details-target">P3</div></details>
</div>
<script>
convertTemplatesToShadowRootsWithin(targets);

testSurroundContents("Normal", "normal-target", T0);
testSurroundContents("Shadow", "T1/target", T1);
testSurroundContents("Multi-level shadow", "T2/H/target", T2);
testSurroundContents("<details>", "details-target", T3);

function testSurroundContents(description, targetPath, newParent) {
    test(function () {
        var target = getNodeInComposedTree(targetPath);
        var range = document.createRange();
        range.selectNode(target);
        assert_throws_dom("HierarchyRequestError", function () {
            range.surroundContents(newParent);
        });
        assert_equals(newParent.firstChild, null, newParent.id + " should not have children after surroundContents()");
    }, description);
}

if (window.testRunner)
    targets.style.display = "none";
</script>
